package com.ruoyi.project.question.info.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.question.info.mapper.QuestionInfoMapper;
import com.ruoyi.project.question.info.domain.QuestionInfo;
import com.ruoyi.project.question.info.service.IQuestionInfoService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 问卷问题表Service业务层处理
 * 
 * @author Bandit
 * @date 2021-12-14
 */
@Service
public class QuestionInfoServiceImpl implements IQuestionInfoService 
{
    @Autowired
    private QuestionInfoMapper questionInfoMapper;

    /**
     * 查询问卷问题表
     * 
     * @param id 问卷问题表主键
     * @return 问卷问题表
     */
    @Override
    public QuestionInfo selectQuestionInfoById(Long id)
    {
        return questionInfoMapper.selectQuestionInfoById(id);
    }

    /**
     * 将已有的问题进行标记
     * @param id
     * @return
     */
    @Override
    public List<QuestionInfo> selectQuestionInfoByQuestionnaireID(Long id) {
        List<QuestionInfo> AllQuestionInfo = questionInfoMapper.selectQuestionInfoList(new QuestionInfo());
        List<QuestionInfo> questionInfos = questionInfoMapper.selectQuestionInfoByQuestionnaireID(id);

        for (QuestionInfo questionInfo : AllQuestionInfo) {
            for (QuestionInfo info : questionInfos) {
                if (info.getId().longValue()==questionInfo.getId().longValue()){
                    questionInfo.setFlag(true);
                    break;
                }
            }
        }
        return AllQuestionInfo;
    }

    @Override
    public List<QuestionInfo> selectQuestionInfoByQuestionnaireIDWithConnID(Long id) {
        return questionInfoMapper.selectQuestionInfoByQuestionnaireIDWithConnID(id);
    }


    /**
     * 查询问卷问题表列表
     * 
     * @param questionInfo 问卷问题表
     * @return 问卷问题表
     */
    @Override
    public List<QuestionInfo> selectQuestionInfoList(QuestionInfo questionInfo)
    {
        return questionInfoMapper.selectQuestionInfoList(questionInfo);
    }

    /**
     * 新增问卷问题表
     * 
     * @param questionInfo 问卷问题表
     * @return 结果
     */
    @Override
    public int insertQuestionInfo(QuestionInfo questionInfo)
    {
        return questionInfoMapper.insertQuestionInfo(questionInfo);
    }

    /**
     * 修改问卷问题表
     * 
     * @param questionInfo 问卷问题表
     * @return 结果
     */
    @Override
    public int updateQuestionInfo(QuestionInfo questionInfo)
    {
        return questionInfoMapper.updateQuestionInfo(questionInfo);
    }

    /**
     * 批量删除问卷问题表
     * 
     * @param ids 需要删除的问卷问题表主键
     * @return 结果
     */
    @Override
    public int deleteQuestionInfoByIds(String ids)
    {
        return questionInfoMapper.deleteQuestionInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除问卷问题表信息
     * 
     * @param id 问卷问题表主键
     * @return 结果
     */
    @Override
    public int deleteQuestionInfoById(Long id)
    {
        return questionInfoMapper.deleteQuestionInfoById(id);
    }
}
